package android.demo.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.demo.service.aidl.ClientActivity;
import android.demo.service.binder.BindingActivity;
import android.demo.service.messenger.MessengerActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ServiceActivity extends ListActivity {
	
	private static final int BINDER = 1;
	private static final int MESSENGER = 2;
	private static final int AIDL = 3;
	
	private SimpleAdapter adapter = null;  
	private ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
	
	{
		Map<String, Object> binder = new HashMap<String, Object>();  
		binder.put("text", "binder(同一Application和进程)");  
		binder.put("type", BINDER);
		data.add(binder);  

		Map<String, Object> messenger = new HashMap<String, Object>();
		messenger.put("text", "messenger(跨进程)");  
		messenger.put("type", MESSENGER);
		data.add(messenger);  
		
		Map<String, Object> aidl = new HashMap<String, Object>();
		aidl.put("text", "aidl");  
		aidl.put("type", AIDL);
		data.add(aidl);  
	}
	
	public void onCreate(Bundle savedInstanceState) {  
		super.onCreate(savedInstanceState);  
		adapter = new SimpleAdapter(this, 
				data, 
				android.R.layout.two_line_list_item, 
				new String[] {"text"}, 
				new int[] {android.R.id.text1}
		);  
		setListAdapter(adapter); 
	}  
	
	protected void onListItemClick(ListView l, View v, int position, long id) {  
		super.onListItemClick(l, v, position, id);  
		int type = (Integer) data.get(position).get("type");
		switch (type) {
			case BINDER :
				startActivity(new Intent(this, BindingActivity.class));
				break;
			case MESSENGER :
				startActivity(new Intent(this, MessengerActivity.class));
				break;
			case AIDL :
				startActivity(new Intent(this, ClientActivity.class));
				break;
		}
	}  
}
